home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / SearchDialog.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  90 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from Tkinter import *
  5. import SearchEngine
  6. from SearchDialogBase import SearchDialogBase
  7.  
  8. def _setup(text):
  9.     root = text._root()
  10.     engine = SearchEngine.get(root)
  11.     if not hasattr(engine, '_searchdialog'):
  12.         engine._searchdialog = SearchDialog(root, engine)
  13.     
  14.     return engine._searchdialog
  15.  
  16.  
  17. def find(text):
  18.     pat = text.get('sel.first', 'sel.last')
  19.     return _setup(text).open(text, pat)
  20.  
  21.  
  22. def find_again(text):
  23.     return _setup(text).find_again(text)
  24.  
  25.  
  26. def find_selection(text):
  27.     return _setup(text).find_selection(text)
  28.  
  29.  
  30. class SearchDialog(SearchDialogBase):
  31.     
  32.     def create_widgets(self):
  33.         f = SearchDialogBase.create_widgets(self)
  34.         self.make_button('Find', self.default_command, 1)
  35.  
  36.     
  37.     def default_command(self, event = None):
  38.         if not self.engine.getprog():
  39.             return None
  40.         
  41.         if self.find_again(self.text):
  42.             self.close()
  43.         
  44.  
  45.     
  46.     def find_again(self, text):
  47.         if not self.engine.getpat():
  48.             self.open(text)
  49.             return False
  50.         
  51.         if not self.engine.getprog():
  52.             return False
  53.         
  54.         res = self.engine.search_text(text)
  55.         if res:
  56.             (line, m) = res
  57.             (i, j) = m.span()
  58.             first = '%d.%d' % (line, i)
  59.             last = '%d.%d' % (line, j)
  60.             
  61.             try:
  62.                 selfirst = text.index('sel.first')
  63.                 sellast = text.index('sel.last')
  64.                 if selfirst == first and sellast == last:
  65.                     text.bell()
  66.                     return False
  67.             except TclError:
  68.                 pass
  69.  
  70.             text.tag_remove('sel', '1.0', 'end')
  71.             text.tag_add('sel', first, last)
  72.             if not self.engine.isback() or first:
  73.                 pass
  74.             text.mark_set('insert', last)
  75.             text.see('insert')
  76.             return True
  77.         else:
  78.             text.bell()
  79.             return False
  80.  
  81.     
  82.     def find_selection(self, text):
  83.         pat = text.get('sel.first', 'sel.last')
  84.         if pat:
  85.             self.engine.setcookedpat(pat)
  86.         
  87.         return self.find_again(text)
  88.  
  89.  
  90.